﻿using System.Windows.Documents;
using System.Windows.Media;

namespace 数据挖掘实验
{
	public static class RichTextFormatter
	{
		/// <summary>
		/// 对文本信息进行处理
		/// </summary>
		/// <param name="text"></param>
		/// <returns>转换好的富文本控件</returns>
		public static Section Format(string text)
		{
			string[] paragraphs = text.Split("\n");
			var section = new Section();
			foreach (var paragraph in paragraphs)
			{
				if (string.IsNullOrEmpty(paragraph))
					continue;
				if (paragraph.StartsWith("w:")) // 以w:开头的表示为警告文本
				{
					section.Blocks.Add(new Paragraph(new Run(paragraph[2..]) { Foreground = Brushes.Orange}));
					continue;
				}
				section.Blocks.Add(new Paragraph(new Run(paragraph)));
			}
			return section;
		}
	}
}
